package com.cskaoyan.service;

import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.model.MarketUser;
import com.cskaoyan.model.MarketUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/12
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    MarketUserMapper userMapper;

    @Override
    public MarketUser findByName(String username) {
        MarketUserExample example = new MarketUserExample();
        example.createCriteria().andUsernameEqualTo(username)
                .andDeletedEqualTo(false);
        List<MarketUser> marketUsers = userMapper.selectByExample(example);
        return marketUsers!=null&&marketUsers.size()==1?marketUsers.get(0):null;
    }

    @Override
    public MarketUser findById(Integer id) {
        MarketUserExample example = new MarketUserExample();
        example.createCriteria().andIdEqualTo(id)
                .andDeletedEqualTo(false);
        List<MarketUser> marketUsers = userMapper.selectByExample(example);
        return marketUsers != null && marketUsers.size() == 1 ? marketUsers.get(0) : null;
    }
}
